
// 或者直接返回整个事件
document.onselectstart = function(){
    return false;
}
var commonTpme = new Function();
var common = new commonTpme();
var mailReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
commonTpme.prototype.loginUrl = '/app/login';//登录
commonTpme.prototype.getVerificationCodeUrl = '/app/getVerificationCode';//获取注册验证码
commonTpme.prototype.resetPasswordsUrl = '/app/resetPasswords';//获取重置密码验证码
commonTpme.prototype.modificationUserPassWordUrl = '/app/modificationUserPassWord';//重置密码
commonTpme.prototype.userRegisterUrl = '/app/userRegister';//注册
commonTpme.prototype.getTenantFromUserUrl = '/app/getTenantFromUser';//获取租户
commonTpme.prototype.getAllProductsNameIdUrl = '/app/getAllProductsNameId';//获取产品
commonTpme.prototype.getDeviceStatusToMtmsUrl = '/app/getDeviceStatusToMtms';//获取实施工况
commonTpme.prototype.getDeviceByPositionUrl = '/app/getDeviceByPosition';//获取设备的位置信息
commonTpme.prototype.TestPatternQueryUrl = '/app/TestPatternQuery';//测试模式配置查询
commonTpme.prototype.TestPatternStoreUrl = '/app/TestPatternStore';//测试模式配置存储
commonTpme.prototype.getDeviceTypeContentUrl = '/app/getDeviceTypeContent';//设备模型属性查询
commonTpme.prototype.CheckRuleQueryUrl = '/app/CheckRuleQuery';//校验规则查询
commonTpme.prototype.CheckRuleStoreUrl = '/app/CheckRuleStore';//存储校验规则
commonTpme.prototype.singleTestResultQueryUrl = '/app/singleTestResultQuery';//单次的执行结果和状态查询
commonTpme.prototype.PressureTestResultsQueryUrl = '/app/PressureTestResultsQuery';//获取设备压力测试的测试详情
commonTpme.prototype.getConfigByIdUrl = '/app/getConfigById';//判断配置是否存在

var deviceErrorMsg = {};
deviceErrorMsg["600"] = '开始测试';
deviceErrorMsg["601"] = '设备上线';
deviceErrorMsg["602"] = '上报数据对比成功';
deviceErrorMsg["620"] = '执行指令中';
deviceErrorMsg["603"] = '下发指令成功';
deviceErrorMsg["660"] = '上线超时';
deviceErrorMsg["661"] = '上报数据对比失败';
deviceErrorMsg["663"] = '设备无可写属性';
deviceErrorMsg["664"] = '调用下发接口失败';
deviceErrorMsg["665"] = '指令下发,设备无反应';
deviceErrorMsg["800"] = '设备上线中(开始测试的起点)';
deviceErrorMsg["804"] = '设备已上线';
deviceErrorMsg["805"] = '设备上报数据对比成功';
deviceErrorMsg["852"] = '执行指令中';
deviceErrorMsg["806"] = '下发指令成功';
deviceErrorMsg["807"] = '设备已复位';
deviceErrorMsg["850"] = '上报数据对比失败';
deviceErrorMsg["851"] = '调用下发接口失败';
deviceErrorMsg["853"] = '设备无可写属性';
deviceErrorMsg["855"] = '设备上线超时';
deviceErrorMsg["856"] = '指令已下发，设备回复超时';
deviceErrorMsg["857"] = 'GPS数据不正确';
commonTpme.prototype.deviceErrorMsg = deviceErrorMsg;


commonTpme.prototype.fadeIn = function (bean, ele) {
    var opacity = parseFloat(bean.style.opacity);
    opacity = opacity || 0;
    var fadeInId = setInterval(function () {
        opacity += 0.05;
        bean.style.opacity = opacity;
        if (opacity >= ele) {
            clearInterval(fadeInId);
        }
    }, 30);
}//fadeIn()
commonTpme.prototype.fadeOut = function (bean, fun) {
    var opacity = parseFloat(bean.style.opacity);
    opacity = opacity || 0;
    var fadeInId = setInterval(function () {
        opacity -= 0.05;
        bean.style.opacity = opacity;
        if (opacity <= 0) {
            clearInterval(fadeInId);
            if (fun == 'clear') {
                document.body.removeChild(bean);
            }
        }
    }, 20);
}//fadeIn()
//显示提示层
//c:要显示的字,b:回调函数,t:显示时长,默认2秒
commonTpme.prototype.showMsgTips = function (content, fun, time) {
    if (content == null) return false;
    time = time || 2000;//设置默认时长
    var Outer = document.createElement("div");
    var inner = document.createElement('div');
    Outer.setAttribute('style', 'width:100%;height:0px;position:fixed;top:40%;z-index:999');//设置样式
    Outer.style.opacity = 0.1;//设置默认不透明度
    document.body.appendChild(Outer); //设置到到body
    commonTpme.prototype.fadeIn(Outer, 0.8);//设置显示不透明度
    inner.setAttribute('style', 'width:50%;max-width:200px;position:relative;margin:0 auto;text-align:center;word-break:break-all;word-wrap:break-word;padding:10px 0px;border-radius:3px;background:rgba(0,0,0,0.5);color:#fff;box-shadow:1px 1px 5px rgba(0,0,0,0.2)');
    inner.innerHTML = content;//插入字体
    Outer.appendChild(inner);//把要显示字符串的div插入到样式div
    setTimeout(function () {//设置显示时长
        commonTpme.prototype.fadeOut(Outer, 'clear');//清楚当前div
        if (typeof fun == 'function') {//回调函数
            fun();
        }
    }, time);//settimeout
}//showMsgTips()


//判断是否是pc端,如果是则为true,手机端为false;
commonTpme.prototype.isPc = function () {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
        "SymbianOS", "Windows Phone",
        "iPad", "iPod"];
    for (var v = 0; v < Agents.length; v++) {//循环对比
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            return false;
            break;
        }
    }//for
    return true;
}//isPc()
//dom对象转换为object对象 
commonTpme.prototype.domToObj = function (content) {
    return (new Function('return ' + content))();
}//domToObj()
//字符串转换为object对象
commonTpme.prototype.strToObj = function (content) {
    return eval("(" + content + ")");
}//strToObj()
//html获取参数
commonTpme.prototype.getParameter = function (content) {
    var reg = new RegExp("(^|&)" + content + "=([^&]*)(&|$)", "i");
    var content = window.location.search.substr(1).match(reg);
    if (content != null) return unescape(content[2]);
    return null;
}//getParameter()
//字符串全部转换为小写
commonTpme.prototype.strToLowercase = function (content) {
    return content.toLowerCase();
}
//将文本字符串编码为一个统一资源标识符
commonTpme.prototype.encodeUri = function (encryption) {
    return encodeURIComponent(encryption);
}
//返回统一资源标识符 (URI) 的一个已编码组件的非编码形式。
commonTpme.prototype.decodeUri = function (Decryption) {
    return decodeURIComponent(Decryption);
}
jQuery.fn.shake = function (intShakes /*Amount of shakes 摇动量 */, intDistance /*Shake distance 摇晃距离*/, intDuration /*Time duration 持续时间*/) {
    this.each(function () {
        var jqNode = $(this);
        jqNode.css({position: 'fixed', top: '0px;'});
        for (var x = 1; x <= intShakes; x++) {
            jqNode.animate({left: (intDistance * -1)}, (((intDuration / intShakes) / 4)))
                .animate({left: intDistance}, ((intDuration / intShakes) / 2))
                .animate({left: 0}, (((intDuration / intShakes) / 4)));
        }
    });
    return this;
};
commonTpme.prototype.errorTips = function (msg, outTime) {//错误提示
    var node = $('.js_tooltips');
    if (outTime == null) outTime = 2000;
    node.text(msg);
    node.show();
    node.shake(5, 10, 400);
    setTimeout(function () {
        node.fadeOut(500);
    }, outTime)
}
commonTpme.prototype.isEmailAvailable = function (value) {//验证邮箱
    if (mailReg.test(value)) {
        return true;
    } else {
        return false;
    }
}